#ifndef __KERNEL_CHUNK_H__
#define __KERNEL_CHUNK_H__

#include "kernel/spinlock.h"

#ifdef __cplusplus
extern "C" {
#endif

struct chunk_stru
{
	unsigned short size;			// in page
	unsigned short addr;			// offset to real start addr (in page)
	unsigned short prev_chunk;
	unsigned short next_chunk;
} PACKED;

typedef struct chunk_stru chunk_t;

struct chunk_mgr
{
	unsigned short user_start;		// allocatable area start (in page) (relative to start addr of vma)
	unsigned short free_chunks;		// count of total free chunks
	unsigned short chunk_list;		// double-link list header
	unsigned short free_user_pages;
	spinlock_t spinlock;
} PACKED;

typedef struct chunk_mgr chunk_mgr_t;

// initialization of chunk
bool init_chunk(vma_t *vma);

// virtual memory allocation
// pgs = pages to be allocated
void* chunk_vmalloc(vma_t *vma, size_t pgs);

// virtual memory free
// pgs = pages to be freed
int chunk_vfree(vma_t* vma, void *_addr, uint pgs);

#ifdef __cplusplus
}
#endif
#endif
/* EOF */
